package com.neusoft.hospital.controller;
/**
 * @author:杨浩杰
 * 测试类 Cidetailedreport
 *	option：六个原始操作（增、删、查<三个查找>、改）
 */
import com.neusoft.hospital.pojo.Cidetailedreport;
import com.neusoft.hospital.service.CidService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(origins = "*" ,allowCredentials = "true")
@RequestMapping("/cid")
public class CidController {
	@Autowired
	CidService cidService;

//===================================================select option========================================================

	/*	select cidetailedreport全部数据列表
	 * 	http://localhost:8080/cid/AllCidList
	 */
	@RequestMapping("/AllCidList")
	public Map<String, Object> AllCidList() throws Exception{
		List<Cidetailedreport> cidList = cidService.findCidBySql();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", "1");
		map.put("cirList", cidList);
		return map;
	}

	/*	select cid 模糊查询
	 * 	http://localhost:8080/cid/getCidByName?name=血
	 */
	@RequestMapping("/getCidByName")
	public Map<String, Object> getCidByName(String name) throws Exception{
		List<Cidetailedreport> cidetailedreportList = cidService.findCidByName(name);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", "1");
		map.put("cirList", cidetailedreportList);
		return map;
	}

	/*	select cid by cidrId
	 * 	http://localhost:8080/cid/getCidByorderId?orderId=1002
	 */
	@RequestMapping("/getCidBycirId")
	public Map<String, Object> getCidByorderId(int orderId) throws Exception{
		List<Cidetailedreport> cidetailedreportList = cidService.findCidByOrderId(orderId);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", "1");
		map.put("cirList", cidetailedreportList);
		return map;
	}



//===================================================insert============================================================
	/*	数据库的增加操作
	 * 	http://localhost:8080/cid/InsetCid?cidrId=22&ciId=22&name="wule"&orderId=22&unit="hh"&maxrange=11&normalValue="dayu"
	 */
	@RequestMapping("/InsetCid")
	public Map<String, Object> InsetCid(HttpSession session, Cidetailedreport cidetailedreport) throws Exception{
		int cidrId = cidetailedreport.getCidrId();
		Cidetailedreport target = cidService.findTaskByCidrId(cidrId);
		Map<String, Object> map = new HashMap<String, Object>();
		if(target == null){
			cidService.insertCid(cidetailedreport);
			map.put("status", "1");
			map.put("url", "/cir_ajax/toSuccess");
		} else {
			map.put("status", "0");
			map.put("infoCirInsert", " the account has already exit");
		}
		return map;
	}




//===================================================update by cidrId============================================================
	/*	update
	 * 	http://localhost:8080/cid/doUpdate?cidrId=11&ciId=11&name="wule"&orderId=12
	 */
	@RequestMapping("/doUpdate")
	public Map<String, Object> doUpdate(HttpSession session, Cidetailedreport cidetailedreport) throws Exception{
		cidService.updateCid(cidetailedreport);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", "1");
		return map;
	}


//===================================================delete============================================================
	/*	delete
	 * 	http://localhost:8080/cid/delByCidrId?cidrId=11
	 */
	@RequestMapping("/delByCidrId")
	public Map<String, Object> delByCidrId(HttpSession session, Cidetailedreport cidetailedreport) throws Exception{
		int count = cidService.deleteCid(cidetailedreport);
		Map<String, Object> map = new HashMap<String, Object>();
		if(count>0){
			map.put("status", "1");
		} else {
			map.put("status", "0");
		}
		return map;
	}

}
